import request from "../utils/request"

export default {
    // 命名空间
    namespace: 'home',
    // 定义数据
    state: {
        title: "第一次使用dva定义数据",
        list: []
    },
    // 修改数据
    reducers: {
        changeTitle(state) {
            state.title = "我修改了"
            return {
                ...state
            }
        },
        setList(state, { res}) {
            state.list = res
            return {
                ...state
            }
        }
    },
    // 异步任务
    effects: {
        *init(action, { call, put }) {
            const res = yield request('https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata')
            yield put({ type: "setList", res: res.data.message })
        }
    },
    // 
    subscriptions: {
        asddgqweqr({ dispatch, history }) {
            // dispatch({ type: "init"})
            // console.log(history)
            debugger
        }
    }
}